package cn.jobstart.data.liePin;

import cn.jobstart.common.FileUtil;
import cn.jobstart.common.StringUtil;
import cn.jobstart.props.FileConfig;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;

/**
 * @author sunke
 * @version 1.0
 * @Description liepin行业
 * @date 2023-11-22 16:07
 */
@Component
public class IndustrysUtil {

    @Resource
    private FileConfig fileConfig;

    private List<Industrys> indTypeList;


    public IndustrysUtil() {


    }

    private void init() {

        String data = FileUtil.readInFile(fileConfig.getRoot() + File.separator + "lie_pin" + File.separator + "industrys.js", "utf-8");

        indTypeList = JSONArray.parseArray(data, Industrys.class);


    }

    public String getCodeByName(String name) {
        if (StringUtil.isNullOrEmpty(name)) {
            return null;
        }

        if (StringUtil.isNullOrEmpty(indTypeList)) {
            init();
        }
        if (StringUtil.isNullOrEmpty(indTypeList)) {
            return null;
        }
        for (Industrys typeItem : indTypeList) {
            if (StringUtil.isNullOrEmpty(typeItem.getChName())) {
                continue;
            }



            /*if (name.equalsIgnoreCase(typeItem.getChName())) {
                return typeItem.getCode();
            }*/
            if (typeItem.getChName().indexOf(name)>=0) {
                return typeItem.getCode();
            }

        }

        return null;

    }


}
